package com.to8to.autotask.rpc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import com.to8to.autotask.util.DBOperaType;
import com.to8to.autotask.util.Utils;
import com.to8to.es.mq.EsWriter;

/**
 * SendMsg2ES.java
 * 作 者：atom.liu
 * 版 本：v2.0
 * 日 期：2014年8月9日
 * 描 述：发送消息给ES，刷新ES。
 */
public class SendMsg2ES
{
    /**
     * 操作类型
     */
    private DBOperaType operaType;

    /**
     * 操作表名 
     */
    private String tableName;

    /**
     * 操作的id集合
     */
    private Collection<String> ids;

    public SendMsg2ES(DBOperaType operaType, String tableName, Collection<String> ids)
    {
        this.operaType = operaType;
        this.tableName = tableName;
        this.ids = ids;
    }

    public SendMsg2ES(DBOperaType operaType, String tableName, String idsStr)
    {
        this.operaType = operaType;
        this.tableName = tableName;
        this.ids = Arrays.asList(idsStr.split(","));
    }

    /**
     * 发送消息给ES
     */
    public void sendMsg()
    {
        if (operaType == DBOperaType.UPDATE)
        {
            if (Utils.isNullOrEmpty(ids))
                return;
            ids = new ArrayList<String>(ids);
            EsWriter.sendUpdateMsg(tableName, ids);
        }
    }

    public static void main(String[] args)
    {
        new SendMsg2ES(DBOperaType.UPDATE, "to8to_jj_smt_zb", " 12864,15725,13652,14042,15195,19534").sendMsg();
    }

    public DBOperaType getOperaType()
    {
        return operaType;
    }

    public void setOperaType(DBOperaType operaType)
    {
        this.operaType = operaType;
    }

    public String getTableName()
    {
        return tableName;
    }

    public void setTableName(String tableName)
    {
        this.tableName = tableName;
    }

    public Collection<String> getIds()
    {
        return ids;
    }

    public void setIds(List<String> ids)
    {
        this.ids = ids;
    }
}
